﻿#region Using Statements
using System;
using Microsoft.Xna.Framework;
#endregion

namespace StarFox.ScreenComponents
{
    /// <summary>
    /// Implementation of a head-up display.
    /// <para>Definition of head-up display effects.</para>
    /// </summary>
    partial class HeadUpDisplay
    {
        #region Collisions

        bool isDanger_Center;
        bool isDanger_Left;
        bool isDanger_Right;

        float dangerTime_Center;
        float dangerTime_Left;
        float dangerTime_Right;

        float dangerAlpha_Center;
        float dangerAlpha_Left;
        float dangerAlpha_Right;

        Rectangle dstRectDanger_Center;
        Rectangle dstRectDanger_Left;
        Rectangle dstRectDanger_Right;

        /// <summary>
        /// Sets the duration of warning effects.
        /// </summary>
        public TimeSpan WarningEffectDuration
        {
            private get;
            set;
        }

        /// <summary>
        /// Shows asteroid collision effect.
        /// </summary>
        /// <param name="type">The type of the collision.</param>
        public void Collision(AsteroidField.CollisionType type)
        {
            switch (type)
            {
                case AsteroidField.CollisionType.LEFT:
                    {
                        isDanger_Left = true;
                        dangerTime_Left = 0.0f;
                        break;
                    }
                case AsteroidField.CollisionType.CENTER:
                    {
                        isDanger_Center = true;
                        dangerTime_Center = 0.0f;
                        break;
                    }
                case AsteroidField.CollisionType.RIGHT:
                    {
                        isDanger_Right = true;
                        dangerAlpha_Right = 0.0f;
                        break;
                    }
            }
        }

        #endregion

        #region Bomb Mode

        HudBar bombModeBar;
        readonly int bombModeBarWidth = 210;
        readonly int bombModeBarHeight = 10;

        bool isBombMode;
        float bombModeTime;

        /// <summary>
        /// Sets the duration of bomb mode effect.
        /// </summary>
        public TimeSpan BombModeDuration
        {
            private get;
            set;
        }

        /// <summary>
        /// Shows power-up effect.
        /// </summary>
        /// <param name="type">The type of the power-up.</param>
        public void PowerUp(PowerUp.PowerUpType type)
        {
            CancelAllEffects();
        }

        /// <summary>
        /// Shows bomb mode activation effect.
        /// </summary>
        public void BombMode()
        {
            CancelAllEffects();
            isBombMode = true;
        }

        #endregion

        private void HeadUpDisplay_Effects()
        {
            Rectangle auxRect;

            auxRect = spriteSheet.SourceRectangle("ARROW_DANGER_CENTER");
            dstRectDanger_Center = Rectangle.Empty;
            dstRectDanger_Center.Width = (int)(auxRect.Width * Screen.Scale);
            dstRectDanger_Center.Height = (int)(auxRect.Height * Screen.Scale);
            dstRectDanger_Center.X = (int)((Screen.Width - dstRectDanger_Center.Width) * 0.5f);
            dstRectDanger_Center.Y = (int)(Screen.Height * 0.33f);

            auxRect = spriteSheet.SourceRectangle("ARROW_DANGER_LEFT");
            dstRectDanger_Left = Rectangle.Empty;
            dstRectDanger_Left.Width = (int)(auxRect.Width * Screen.Scale);
            dstRectDanger_Left.Height = (int)(auxRect.Height * Screen.Scale);
            dstRectDanger_Left.X = (int)(Screen.Width * 0.40f);
            dstRectDanger_Left.Y = (int)((Screen.Height - dstRectDanger_Left.Height) * 0.5f);

            auxRect = spriteSheet.SourceRectangle("ARROW_DANGER_RIGHT");
            dstRectDanger_Right = Rectangle.Empty;
            dstRectDanger_Right.Width = (int)(auxRect.Width * Screen.Scale);
            dstRectDanger_Right.Height = (int)(auxRect.Height * Screen.Scale);
            dstRectDanger_Right.X = (int)(Screen.Width * 0.5725f);
            dstRectDanger_Right.Y = (int)((Screen.Height - dstRectDanger_Right.Height) * 0.5f);

            bombModeBar = new HudBar(Screen, (int)(bombModeBarWidth * Screen.Scale), (int)(bombModeBarHeight * Screen.Scale)) { Color = Color.Aqua };
            bombModeBar.X = (int)((Screen.Width - bombModeBar.Width) * 0.5f);
            bombModeBar.Y = (int)(Screen.Height * 0.625f);

            WarningEffectDuration = TimeSpan.FromMilliseconds(1000);
            BombModeDuration = TimeSpan.FromMilliseconds(1000);
        }

        private void CancelAllEffects()
        {
            isDanger_Center = false;
            dangerTime_Center = 0.0f;

            isDanger_Left = false;
            dangerTime_Left = 0.0f;

            isDanger_Right = false;
            dangerTime_Right = 0.0f;
        }
    }
}
